package cn.loan.spring.session;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration;
import org.springframework.session.web.context.AbstractHttpSessionApplicationInitializer;

/**
 * @Author: 毛苏宇
 * @Description: HttpSession的相关配置
 * AbstractHttpSessionApplicationInitializer必须继承,它将自动向servlet容器中加入springSessionRepositoryFilter
 * @Date: Create in 13:52 2019/4/28
 */
@Configuration
public class SpringSession extends AbstractHttpSessionApplicationInitializer  {

    /**
     * 配置SpringSession
     *
     * @return
     */
    @Bean
    public RedisHttpSessionConfiguration redisHttpSessionConfiguration() {
        RedisHttpSessionConfiguration redisHttpSessionConfiguration = new RedisHttpSessionConfiguration();
        //session过期时间,30分钟
        redisHttpSessionConfiguration.setMaxInactiveIntervalInSeconds(1800);
        return redisHttpSessionConfiguration;
    }


    /**
     * 配置Session监听器
     * @return
     */
/*    @Bean
    public SessionEventHttpSessionListenerAdapter sessionEventHttpSessionListenerAdapter(){
        List<HttpSessionListener> httpSessions=new ArrayList<HttpSessionListener>();
        httpSessions.add(new SessionListener());
        return new SessionEventHttpSessionListenerAdapter(httpSessions);
    }*/

}
